/* 
    1. 新建一个axios 实例
    2. 返回的数据进行处理
*/
import axios from 'axios';
import { Toast } from 'vant';
let instance = axios.create({
    // baseURL: 'https://v2.alapi.cn/',
    timeout: 10000,
});
/*  配置请求和响应的拦截器 */
instance.interceptors.request.use(
    // 加遮罩
    (config) => {
        console.log(config);
        Toast.loading({
            message: '加载中...',
            forbidClick: true,
            duration: 0,
        });
        /*     :authority: m.haodf.com
:method: POST
:path: /nindex/home/AjaxAreaList */
        // config.headers[':authority'] = 'm.haodf.com';
        // config.headers[':method'] = 'POST';
        // config.headers[':path:'] = '/nindex/home/AjaxAreaList ';

        return config;
    },
    (error) => {
        Toast.clear();
        return Promise.reject(error);
    },
);
instance.interceptors.response.use(
    (response) => {
        // 取消遮罩
        Toast.clear();
        console.log(response);
        return response.data;
    },
    (error) => {
        Toast.clear();
        return Promise.reject(error);
    },
);
export default instance;
